/*
 * Copyright (C) 2012 mAPPn.Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mol.market.common.util;

import com.mol.market.R;
import com.mol.market.demo.widget.BaseFragmentWrapper.WidthMatching;

/**
 * 根据不同的屏幕大小和规则，动态创建和配置各种属性。
 * @author Chaos	
 * @date 2013-3-4 
 */
public class ScreenRules {
    
    /**
     * 页面规则 
     */
    public enum Rules {
        /**
         * 产品浏览列表(不包含下载按钮,首页)
         */
        Product, 
        /**
         * 产品下载列表(包含下载按钮的List)
         */
        Download
    }
    
    /**
     * 根据屏幕宽度不同，获取不同的布局
     * @param 
     */
    public static int getLayout(WidthMatching matching,Rules rule){
        
        int layout_common = 0;
        int layout_large  = 0;
        
        switch (rule) {
        case Product:
            layout_common = R.layout.common_product_list_item;
            layout_large  = R.layout.common_product_list_item_large;
            break;
        case Download:
            layout_common = R.layout.common_download_list_item;
            layout_large  = R.layout.common_download_list_item_large;
            break;
        }
        
        switch (matching) {
        case W320:
            return layout_common;
        case W360:
            return layout_large;
        case W533:
            return layout_common;
        case W640:
            return layout_large;
        default:
            throw new IllegalArgumentException("can not find Matching the " + 
                    "width of the");
        }
    }
    
    /**
     * 返回设置的列数
     */
    public static int getNumColumns(WidthMatching matching,Rules rule) {
        int base = 0;
        switch (rule) {
        case Download:
            base = 1;
            break;
        case Product:
            base = 2;
            break;
        }
        switch (matching) {
        case W320:
        case W360:
            return base;
        case W533:
        case W640:
            return base + 1;
        default:
            throw new IllegalArgumentException("can not find Matching the " + 
                    "width of the");
        }
    }
}
